/**
 * 
 */
package de.guidoludwig.jtm.server;

import java.util.List;

import javax.persistence.EntityManager;

import org.hibernate.search.jpa.FullTextEntityManager;
import org.hibernate.search.jpa.Search;

import de.guidoludwig.jtm.domain.Show;

/**
 * @author guido
 * 
 */
public class ShowRepository extends AbstractRepository<Show> {

	public ShowRepository() throws Exception {
		super(Show.class);
	}

	@Override
	protected String[] getSearchFields() {
		return new String[] { Show.SEARCHFIELD_ARTIST_NAME,
				Show.SEARCHFIELD_LOCATION_CITY,
				Show.SEARCHFIELD_LOCATION_COUNTRY_CODE,
				Show.SEARCHFIELD_LOCATION_COUNTRY_NAME,
				Show.SEARCHFIELD_LOCATION_VENUE, Show.SEARCHFIELD_NAME,
				Show.SEARCHFIELD_SHOW_DATE };
	}
	
	public void removeShowsByArtist(String artistOID) {
		throw new UnsupportedOperationException("Not yet implemented");
	}

	public void reindex() {
		System.out.println("Indexing SHOWS" );
		EntityManager em = Server.getInstance().createEntityManager();
		FullTextEntityManager fullTextEntityManager = Search
				.getFullTextEntityManager(em);

		final List<Show> entries = em.createQuery("select a from Show a")
				.getResultList();
		for (Show a : entries) {
			System.out.println("Indexing " + a.getName() + "/" + a.getShowDate());
			fullTextEntityManager.index(a);
		}
		em.close();

	}
}